<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>todoList</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .container {
            width: 800px;
            margin: 100px auto;
        }

        .container input {
            border: none;
            outline: none;
            border-bottom: 1px solid gray;
            width: 300px;
            height: 40px;
            font-size: 18px;
        }

        .container button {
            border: none;
            outline: none;
            background-color: blueviolet;
            height: 40px;
            width: 100px;
            text-align: center;
            color: white;
            cursor: pointer;
        }

        ul,
        li {
            list-style: none;
        }

        li {
            line-height: 40px;
            cursor: pointer;
        }
    </style>
    <!-- 
        todolist要求
         1. 点击确定按钮，将输入框内容作为ul的子元素li添加到下面，清空输入框
         2. 点击li，删除点击的li元素

         分析: 1. 点击确定按钮,事件绑定
               2. 将输入框内容作为ul的子元素li添加到下面
                   创建li元素,内容来自输入框

               3. 清空输入框
     -->
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
    <div class="container">
        <input type="text" name="message" id="msg" v-model="content"><button @click="onAdd">确定</button>
        <ul>
            <li v-for="(item,index) in list" @click="onDelete(index)">{{item}}</li>
        </ul>
    </div>

    <script>
        const Todo = {
            data() {
                return {
                    list: ['html', 'css', 'javascript'],
                    content: ''
                }
            },
            methods: {
                onDelete(index) {
                    this.list.splice(index, 1)
                },
                onAdd() {
                    this.list.push(this.content)
                    this.content = ''
                }
            }
        }

        Vue.createApp(Todo).mount('.container')



    </script>
</body>

</html>